﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace net.entity.framework
{
      public enum DataClient
    {
        SqlClient,
        SqlCEClient,
        MySqlClient,
        OleDbClient,
        OracleClient,
        SQLite
    }

    public sealed class DbClient
    {
        #region Static Members
        // ReSharper disable InconsistentNaming
        public static readonly DbClient SqlClient = new DbClient(DataClient.SqlClient, "System.Data.SqlClient");
        public static readonly DbClient SqlCEClient = new DbClient(DataClient.SqlCEClient, "System.Data.SqlServerCe.3.5");
        public static readonly DbClient MySqlClient = new DbClient(DataClient.MySqlClient, "MySql.Data.MySqlClient");
        public static readonly DbClient OleDbClient = new DbClient(DataClient.OleDbClient, "System.Data.OleDb");
        public static readonly DbClient OracleClient = new DbClient(DataClient.OracleClient, "System.Data.OracleClient");
        public static readonly DbClient SQLite = new DbClient(DataClient.SQLite, "System.Data.SQLite");

        public static readonly List<DbClient> RegisteredClients
            = new List<DbClient> {
                                     SqlClient,
                                     SqlCEClient,
                                     MySqlClient,
                                     OleDbClient,
                                     OracleClient,
                                     SQLite
                                 };
        // ReSharper restore InconsistentNaming
        #endregion

        #region Properties

        public DataClient Type { get; private set; }
        public string ProviderName { get; private set; }

        public string Key
        {
            get { return ProviderName.ToLower(); }
        }

        #endregion

        #region Constructor

        public DbClient(DataClient type, string providerName)
        {
            Type = type;
            ProviderName = providerName;
        }

        #endregion
    }
    public class TransactionMaster
    {
        private DbTransaction transaction;
        public TransactionMaster(DbTransaction transaction) {
            this.transaction = transaction;
        }

    }
    public class BatchQuery {
        public static void BatchUpdate(DataTable dataTable, Int32 batchSize)
        {
            // Assumes GetConnectionString() returns a valid connection string.
            string connectionString = "";//GetConnectionString();

            // Connect to the AdventureWorks database.
            using (SqlConnection connection = new
              SqlConnection(connectionString))
            {

                // Create a SqlDataAdapter.
                SqlDataAdapter adapter = new SqlDataAdapter();

                // Set the UPDATE command and parameters.
                adapter.UpdateCommand = new SqlCommand(
                    "UPDATE Production.ProductCategory SET "
                    + "Name=@Name WHERE ProductCategoryID=@ProdCatID;",
                    connection);
                adapter.UpdateCommand.Parameters.Add("@Name",
                   SqlDbType.NVarChar, 50, "Name");
                adapter.UpdateCommand.Parameters.Add("@ProdCatID",
                   SqlDbType.Int, 4, "ProductCategoryID");
                adapter.UpdateCommand.UpdatedRowSource = UpdateRowSource.None;

                // Set the INSERT command and parameter.
                adapter.InsertCommand = new SqlCommand(
                    "INSERT INTO Production.ProductCategory (Name) VALUES (@Name);",
                    connection);
                adapter.InsertCommand.Parameters.Add("@Name",
                  SqlDbType.NVarChar, 50, "Name");
                adapter.InsertCommand.UpdatedRowSource = UpdateRowSource.None;

                // Set the DELETE command and parameter.
                adapter.DeleteCommand = new SqlCommand(
                    "DELETE FROM Production.ProductCategory "
                    + "WHERE ProductCategoryID=@ProdCatID;", connection);
                adapter.DeleteCommand.Parameters.Add("@ProdCatID",
                  SqlDbType.Int, 4, "ProductCategoryID");
                adapter.DeleteCommand.UpdatedRowSource = UpdateRowSource.None;

                // Set the batch size.
                adapter.UpdateBatchSize = batchSize;

                // Execute the update.
                adapter.Update(dataTable);
            }
        }
    }
}
